﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class Bom_SubNodeController : BaseApiController
    {
        #region DI

        public Bom_SubNodeController(IBom_SubNodeBusiness bom_SubNodeBus)
        {
            _bom_SubNodeBus = bom_SubNodeBus;
        }

        IBom_SubNodeBusiness _bom_SubNodeBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Bom_SubNodeDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _bom_SubNodeBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 获取bom树形菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Bom_SubNodeTreeDTO>> GetTreeSubListAsyncs()
        {
            return await _bom_SubNodeBus.GetTreeBomListAsyncs();
        }
        [HttpPost]
        public async Task<Bom_SubNode> GetTheData(IdInputDTO input)
        {
            return await _bom_SubNodeBus.GetTheDataAsync(input.id);
        }
        [HttpPost]
        public async Task<List<treedto>> GetTreeListAsync(string ParentId, string Like) {
            var res = await _bom_SubNodeBus.GetMaterialTypeListAsync(ParentId, Like);
            return res;
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Bom_SubNode data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bom_SubNodeBus.AddDataAsync(data);
            }
            else
            {
                await _bom_SubNodeBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bom_SubNodeBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}